

<html>

<head>
    <title>User Login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href  = "css/bootstrap.min.css" rel ="stylesheet">
	<link href  = "css/bootstrap.min.css" rel ="stylesheet">
	<link rel="stylesheet" type="text/css" href="styles/tasks4.css" media="screen"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
	<script src="scripts/jquery-2.0.3.js"></script>
	<script src="js/bootstrap.js"></script>
   <A NAME="top">
   
	<script>
        $(document).ready(function() {
                    
					//alert(document.cookie);
					
					
					if(document.cookie == ""){
						
						alert("Not Logged In")
						window.location.href = "http://localhost:8080/formswebapp/login.html"
					
					}
					
					
                    $("#btnCreateUser").click(function() {
					
                        alert("clicked");
                        var newUserName = document.getElementById("t_userName").value;
                        var newUserPassword = document.getElementById("t_userPassword").value;
						var c = document.cookie;
                        var theData = "newName=" + newUserName + "&" + "newPassword=" + newUserPassword + "&" + c;

                        alert("Sending: " + theData);
                        var theUrl = "http://localhost:8080/formswebapp/resources/user";
                        $.ajax({
                            url: theUrl,
                            type: "",
                            dataType: "text",
                            contentType: "application/x-www-form-urlencoded",
                            data: theData,

                            success: function(result, status, jqxhr) {
                                alert("success: " + status);

                                
                            
                            },
                            error: function(xhr, status, errorThrown) {
                                alert("error: " + status + " e: " + errorThrown);
                             
                            }
                        });
						
                    });

                    $("#updateBtn").click(function() {
                        alert("clicked");
                        var userName = document.getElementById("updateName").value;
                        var userPass = document.getElementById("updatePass").value;
                        var Id = document.getElementById("userId").value;
                        var theData = "username=" + userName + "&" + "password=" + userPass;

                        alert("Sending: " + theData);
                        $.ajax({
                            url: "http://localhost:8080/formswebapp/resources/user/" + Id,
                            type: "PUT",
                            dataType: "text",
                            contentType: "application/x-www-form-urlencoded",
                            data: theData,

                            success: function(result, status, jqxhr) {
                                alert("success: " + status);
                                var userArray = JSON.parse(result);
                                alert(userArray);
                                var output = "<h3>Updated User</h3>";
                                output += "<ul>"
                                for (var i = 0; i < userArray.length; i++) {
                                    output += "<li>" + "Id updated: " + userArray[i].id + "</li>";
                                }
                                output += "</ul>";
                                alert(output);
                                $("#p_updateUser").html(output);
                            },

                            error: function(xhr, status, errorThrown) {
                                alert("error: " + status + " e: " + errorThrown);
                            }
                        });
                    });

                    $("#btnSearchUser").click(function() {
                      
                    
						var c = document.cookie;
						alert(c);
						
						

                        var theUrl = "http://localhost:8080/formswebapp/resources/user/" + c;

                        $.ajax({
                            url: theUrl,
                            type: "GET",
                            dataType: "text",
							
                            success: function(result, status, jqxhr) {
                                alert("success");
                                var userArray = JSON.parse(result);
                               
                                var output = "<h3>User By Id & Name</h3>";
                                output += "<ul>"
                                for (var i = 0; i < userArray.length; i++) {
                                    output +=  "Id: " + userArray[i].id + " , Name: " + userArray[i].userName + userArray[i].telepohone;
                                }
                                output += "</ul>";
                                alert(output);
                                $("#p_searchUser").html(output);
                            },
                            error: function(xhr, status, errorThrown) {
                               alert("error: " + status + " e: " + errorThrown);
                                $("#p_searchForm").html("Error:" + xhr.status + " " + xhr.statusText);
                            }
                        });
                    });

                    $("#btnDeleteUser").click(function() {
                        
                        var userId2 = document.getElementById("t_userId2").value;
				
                        var c = document.cookie;
						alert(c);
						var theData = c;

                        
                        $.ajax({
                            url: "http://localhost:8080/formswebapp/resources/user/" + userId2,
                            type: "DELETE",
                            dataType: "text",
							data: theData,

                            success: function(result, status, jqxhr) {
                                alert("success: " + status);
                                var userArray = JSON.parse(result);
                                alert(userArray);
                                var output = "<h3>Deleted User</h3>";
                                output += "<ul>"

                                $("#p_deleteUser").html(output);
                            },
                            error: function(xhr, status, errorThrown) {
                                alert("error: " + status + " e: " + errorThrown);
                            }

                        });
                    });
					
					 $("#btnLogout").click(function() {
                        alert("Logging out...");
						var c = document.cookie;
                        var theData = c;

						document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
						
                        //alert("Sending: " + theData);
                        $.ajax({
                            url: "http://localhost:8080/formswebapp/resources/authsession/" + c,
                            type: "DELETE",
                            dataType: "text",
                            data: theData,
							
							
							
                            success: function(result, status, jqxhr) {
                                //alert("success: " + status);
                                var userArray = JSON.parse(result);
                                //alert(userArray);
                                var output = "<h3>Log Out</h3>";
                                window.location.replace("login.html")

                             $('.HiddenInput').val(output);
                            },
                            error: function(xhr, status, errorThrown) {
                                //alert("error: " + status + " e: " + errorThrown);
                            }

                        });
                    });
				
                    $("#btnLogin").click(function() {
                            
                            var loginName = document.getElementById("t_loginName").value;
                            var loginPass = document.getElementById("t_loginPass").value;
                            var dataObj = "loginName=" + loginName + "&" + "loginPass=" + loginPass;

							
                            var theUrl = "http://localhost:8080/formswebapp/resources/authsession";
                            $.ajax({
                                url: theUrl,
                                type: "POST",
                                dataType: "text",
                                contentType: "application/x-www-form-urlencoded",
                                data: dataObj,

                                success: function(result, status, jqxhr) {
                                    alert("success: " + status);

                                    var token = JSON.parse(result);
                                  
									var e = new Date;
									e.setTime(e.getTime()+(60*10*1000));
									var expires = "; expires="+e.toGMTString();
									document.cookie = "token="+token+expires;
									
									$('.HiddenInput').val(token);
									alert(document.cookie);
                                    var output = "<h3>Logged In</h3>";

                                },
                                error: function(xhr, status, errorThrown) {
                                    alert("error: " + status + " e: " + errorThrown);
                                }
                            });

                       });

                   } );				
    </script>
</head>

<body>
<!--Header-->
	<div class = "navbar navbar-inverse navbar-static-top">
		<div class="container">
			<div class = "navbar-header">
				<div class="tut-container-img">
						<img class="img-responsive" src="cculogo.png" alt=""></a>
					</div>
						
				<button class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
					<span class = "icon-bar"></span>
					<span class = "icon-bar"></span>
					<span class = "icon-bar"></span>
				</button><!--Create button for mobile site-->
			</div>
			<div class = "collapse navbar-collapse navHeaderCollapse">
				<ul class = "nav navbar-nav navbar-right">
					<li><a href = "user.html">Home</a></li>
					
					<li class = "dropdown">
						<a href = "#" class = "dropdown-toggle" data-toggle ="dropdown">All Forms<b class="caret"></b></a>
						<ul class = "dropdown-menu">
							<li><a href = "courserepeat.html">Course Repeat Form</a></li>
							<li><a href = "coursesub.html">Course Substitution Form</a></li>
							<li><a href = "transcript.html"> Transcript Form</a></li>
							<li><a href = "specialpermission.html"> Special Permission Form</a></li>

						</ul>
					</li>
					<li class = "dropdown">
						<a href = "#" class = "dropdown-toggle" data-toggle ="dropdown">Social Media <b class="caret"></b></a>
						<ul class = "dropdown-menu">
							<li><a href = "http://twitter.com">Twitter</a></li>
							<li><a href = "http://facebook.com">Facebook</a></li>
							<li><a href = "https://plus.google.com/">Google+</a></li>
							<li><a href = "http://instagram.com">Instagram</a></li>
						</ul>
					</li>
					<li><a href = "#about" data-toggle ="modal">About</a></li>
					<li><a href = "#contact" data-toggle ="modal">Contact</a></li>
					<li>
						<a class="navbar-brand" href="setting.html">
							<i class="glyphicon glyphicon-cog"></i>
						</a>
					</li>	
					<li>
						<button type="button" id="btnLogout" class="btn btn-default navbar-btn">Logout</button>
					</li>
					<li>
						<form class="navbar-form" role="search">
						<div class="input-group">
							<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
							<div class="input-group-btn">
								<button class="btn btn-default" type="search"><i class="glyphicon glyphicon-search"></i></button>
							</div>
						</div>
						</form>		
					</li>

				</ul>
			</div>	
		</div>
	</div>		
	<div class = "container">
		<div id="myCarousel" class ="carousel slide">
				<ol class ="carousel-indicators">
					<li data-target = "#myCarousel" data-slide-to ="0" class="active"></li>
					<li data-target = "#myCarousel" data-slide-to ="1"></li>
					<li data-target = "#myCarousel" data-slide-to ="2"></li>
				</ol>
				
				<div class = "carousel-inner">
					<div class ="item active">
						<img src ="img/football2.jpg" alt="football" class= "img-responsive">
						<div class = "carousel-caption">
						</div>
					</div>	
					<div class ="item ">
						<img src ="img/mobileap.jpg" alt="mobile" class= "img-responsive">
						<div class = "carousel-caption">
						</div>
					</div>
					<div class ="item ">
						<img src ="img/swainhall.jpg" alt="hall" class= "img-responsive">
						<div class = "carousel-caption">
						</div>
					</div>	
				</div>
				<a class ="carousel-control left" href = "#myCarousel" data-slide = "prev">
					<span class ="icon-prev"></span>
				</a>
		</div>
	</div>	
	<div class = "jumbotron text-center">
		<div class = "container">
			<h2>Welcome!</h2>
			<p>Here you can view all your forms.</p>
			<div class="btn-group">
			  <a href = "formList.html" type="button" class="btn btn-default">View All Forms &nbsp &nbsp <span class="glyphicon glyphicon-hand-left"></span></a>
			</div>
		</div>
	</div>
	<div class = "modal fade" id = "contact" role = "dialog">
			<div class = "modal-dialog">
				<div class = "modal-content">
					<form class = "form-horizontal">
						<div class = "modal-header">
							<h4>Contact Support</h4>
						</div>
						<div class = "modal-body">
							
							<div class ="form-group">
								<label for ="contact-name" class = "col-lg-2 control-label">Name:</label>
								<div class="col-lg-10">
									<input type ="text" class ="form-control" id ="contact-name" placeholder="Full Name">
								</div>
							</div>
						
							<div class ="form-group">
									<label for ="contact-email" class = "col-lg-2 control-label">Email:</label>
									<div class="col-lg-10">
										<input type ="email" class ="form-control" id ="contact-name" placeholder="you@example.com">
									</div>	
							</div>
							
							<div class ="form-group">
									<label for ="contact-message" class = "col-lg-2 control-label">Message:</label>
									<div class="col-lg-10">
										<textarea  class="form-control" rows =10"></textarea>
									</div>
							</div>
							
							
							
							<div class = "modal-footer">
								<a class = "btn btn-default" data-dismiss = "modal">Close</a>
								<button class ="btn btn-primary" type="submit">Submit</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		
		<div class = "modal fade" id = "about" role = "dialog">
			<div class = "modal-dialog">
				<div class = "modal-content">
					<form class = "form-horizontal">
						<div class = "modal-header">
							<h4>About</h4>
						</div>
						<div class = "modal-body">
							<div class ="form-group">
								<p> CSCI490</p>
								<p> Richard A. Roman</p>
								<p> Hubert Walton</p>
								<p> Ryan Grogan</p>
							</div>
							<div class = "modal-footer">
								<a class = "btn btn-default" data-dismiss = "modal">Close</a>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	
	
	
	<div class "container"><!--total no more than 12  -->
			<div class="col-sm-4 col-sm-3">
				<div class="tut-container">
					<div class="tut-container-img">
						<img class="img-responsive" src="cculogo.png" alt=""></a>
					</div>
					<div class="tut-container-content"><h4><a href="">Transcript</a>
						</h4><p>Do you need a Transcript form?</p>
					</div>					
					<div class="tut-container-content"><p class="tut-container-progress text-muted"><span class="glyphicon glyphicon-time"></span> COMING SOON</p></div><hr>
					<div class="btn-group">
					  <button type="button" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown">
						Action <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
						<li><a href="#">View</a></li>
						<li><a href="transcript.html">Create</a></li>
					  </ul>
					</div>
				</div>
			</div>

			<div class="col-sm-4 col-sm-3">
				<div class="tut-container">
					<div class="tut-container-img">
						<img class="img-responsive" src="cculogo.png" alt=""></a>
					</div>
					<div class="tut-container-content"><h4><a href="">Course Substitution</a>
						</h4><p>Do you need a Course Substitution form?</p>
					</div>					
					<div class="tut-container-content"><p class="tut-container-progress text-muted"><span class="glyphicon glyphicon-time"></span> COMING SOON</p></div><hr>
					<div class="btn-group">
					  <button type="button" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown">
						Action <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
						<li><a href="#">View</a></li>
						<li><a href="coursesub.html">Create</a></li>
					  </ul>
					</div>
				</div>
			</div>
			<div class="col-sm-4 col-sm-3">
				<div class="tut-container">
					<div class="tut-container-img">
						<img class="img-responsive" src="cculogo.png" alt=""></a>
					</div>
					<div class="tut-container-content"><h4><a href="">Course Repeat</a>
						</h4><p>Do you need a Course Repeat form?</p>
					</div>					
					<div class="tut-container-content"><p class="tut-container-progress text-muted"><span class="glyphicon glyphicon-time"></span> COMING SOON</p></div><hr>
					<div class="btn-group">
					  <button type="button" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown">
						Action <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
						<li><a href="#">View</a></li>
						<li><a href="courserepeat.html">Create</a></li>
					  </ul>
					</div>
				</div>
			</div>
			
			<div class="col-sm-4 col-sm-3">
				<div class="tut-container">
					<div class="tut-container-img">
						<img class="img-responsive" src="cculogo.png" alt=""></a>
					</div>
					<div class="tut-container-content"><h4><a href="">Special Permission</a>
						</h4><p>Do you need a Special Permission form?</p>
					</div>					
					<div class="tut-container-content"><p class="tut-container-progress text-muted"><span class="glyphicon glyphicon-time"></span> COMING SOON</p></div><hr>
					<div class="btn-group">
					  <button type="button" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown">
						Action <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
						<li><a href="#">View</a></li>
						<li><a href="specialpermission.html">Create</a></li>
					  </ul>
					</div>
				</div>
			</div>
			
	<div id= "btt">	
	<A HREF="#top" class="btn btn-default">Back To Top</A>
	</div>
	<!--Footer-->
	
	<div class = "navbar navbar-inverse navbar-fixed-bottom">
		<div>
			<p class = "navbar-text pull-right">2014 Coastal Carolina University | P.O. Box 261954, Conway, SC 29528-6054 USA | +1 843-347-3161</p>
		</div>
	</div>

	
</body>

</html>